import math
'''
// todo:
   binary file 
   without 'Iteration'
'''
def read_converg_file(converg_path,log_path):
    converg_file = open(converg_path)
    id_converg = converg_file.readline().strip().split(',')
    cnt_steps = len(id_converg)
    while not id_converg == ['']:
        if  cnt_steps > 2 and (not id_converg[1] == id_converg[2]):
            # binary file (empty)
            print id_converg[0]
            #print cnt_steps
            #print id_converg[1]
            #log_file = open(log_path,'a')
            #log_file.write(id_converg[0])
            id_log_list = []
            signal = 1
            for i in range(1, cnt_steps):    
                print id_converg[i]
                if id_converg[i] == 'EDDAV':  #without iteration
                    signal = 0
                    break
                f_id_converg = float(id_converg[i])
                print f_id_converg
                log_id_converg = math.log10(f_id_converg)
                w_log = float('%.4f' % log_id_converg)
                id_log_list.append(w_log)
                #print log_id_converg
            if signal == 1:
                log_file = open(log_path,'a')
                log_file.write(id_converg[0])
                for j in range(len(id_log_list)):
                    log_file.write(','+ str(id_log_list[j]))
                log_file.write('\n')
                log_file.close() 
            #break
        id_converg = converg_file.readline().strip().split(',')     
        cnt_steps = len(id_converg)
        print cnt_steps
    converg_file.close()

if __name__ == '__main__':
    #converg_path = '/home/lss/vasp_data/201711_converg.csv'
    #log_path = '/home/lss/vasp_data/201711_log_less60.csv'
    converg_path = sys.agrv[1]
    log_path = sys.agrv[2]

    read_converg_file(converg_path,log_path)
